/*
	json={
		count:60,		//总计时时长
		parent:"#id",	// 父元素
		css:{			//样式
			color:black
		},
		alert:"xxx"
	}
*/


//  存在this指向问题！！  需解决
var countTime=function(json){
	if (!json||!json.count||!json.parent) {
		return;
	}
	this.count=json.count;
	this.parent=json.parent;
	this.css=json.css||null;
	this.alert=json.alert;
}
countTime.prototype={
	init:function(){
		var parent=document.getElementById(this.parent);
		this.setHTML();
		this.setCss();
		parent.appendChild(this.newEle);
		this.counts();
	},
	setHTML:function(){
		var inner="<span id='count-min'>00</span>"
					+" : "
					+"<span id='count-sec'>00</span>"
		this.newEle=document.createElement("div");
		this.newEle.innerHTML=inner;
	},
	setCss:function(){
		for(var i in this.css){
			this.newEle.style[i]=this.css[i];
		}
	},
	counts:function(){
		var n=0;
		var min=0;
		var sec=0;
		var count_min=document.getElementById("count-min");
		var count_sec=document.getElementById("count-sec");
        var count=this.count;
        var alertWord=this.alert;
        var flag=false;
		var time=setInterval(function(){
			min=parseInt(n/60)>=10?parseInt(n/60):'0'+parseInt(n/60);
			sec=parseInt(n%60)>=10?parseInt(n%60):'0'+parseInt(n%60);
			count_min.innerHTML=min;
			count_sec.innerHTML=sec;
			if (n>count&&!flag) {			//this问题
				// clearInterval(time);
                flag=true;
				alert(alertWord);
			}
			n++;
		},1000)
	}

}
